//-----------------------------------------------------------------------------
// Name: InanimateObjectManager.cpp
// Auth: Dante Ratto, Paul Godfrey, Rob Darty
// Desc: Keeps a list of InanimateObjects
//-----------------------------------------------------------------------------

#include "InanimateObjectManager.h"
#include "InanimateObject.h"
#include <iostream>
#include <windows.h>

using namespace std;

cInanimateObjectManager gInanimateObjectManager;

//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cInanimateObjectManager* GetInanimateObjectManager()
{
	return &gInanimateObjectManager;
}

cInanimateObjectManager::cInanimateObjectManager()
{
}

cInanimateObjectManager::~cInanimateObjectManager()
{
}

//Adds one InanimateObject to the manager - queue position is irrelevent so it always adds to the front.
void cInanimateObjectManager::AddInanimateObject(enum eInanimateType eType, float x, float y, float z)
{
	cInanimateObject* newInanimateObject = GetInanimateObject();
	newInanimateObject->SetPosition(x, y, z);
	newInanimateObject->SetType(eType);
//	liInanimateObject.push_front(newInanimateObject);
	liInanimateObject.push_back(*newInanimateObject);
}

void cInanimateObjectManager::AddInanimateObjectFence(enum eInanimateType eType, float x, float z, float xoff, float zoff)
{
	cInanimateObject* newInanimateObject = GetInanimateObject();
	newInanimateObject->SetPosition(x, 0, z);
	newInanimateObject->SetType(eType);
	newInanimateObject->SetXOffset(xoff);
	newInanimateObject->SetZOffset(zoff);
	newInanimateObject->SetBounding(x-xoff-0.5f, x+xoff+0.5f, 0, 3.0f, z-zoff-0.5f, z+zoff+0.5f);
//	liInanimateObject.push_front(newInanimateObject);
	liInanimateObject.push_back(*newInanimateObject);
}

//Updates all the InanimateObjects locations and draws them
void cInanimateObjectManager::UpdateInanimateObject(float elapsedTimeS)
{
		itInanimateObject = liInanimateObject.begin();
		while (itInanimateObject != liInanimateObject.end())
		{
			//TODO: Part  of leak in this DRAW - tree related
			itInanimateObject->Draw(itInanimateObject->GetType());
			//itInanimateObject->Draw(kFence);			
			itInanimateObject++;
		}
}

list<cInanimateObject>* cInanimateObjectManager::GetInanimateList()
{
	return &liInanimateObject;
}